using System;
using System.Collections.Generic;
using System.Text;

namespace SharpMud.Server.Systems.Scripting.Processing.Source
{
    public sealed class NotCompileableException : System.Exception
    {
        private IScriptSourceHandle   _ScriptSource;
        private IScriptCompileResults _LastCompileResults;
        private bool _CustomMessageProvided;

        private NotCompileableException()
            : base()
        { }

        public NotCompileableException(IScriptSourceHandle scriptSource, IScriptCompileResults lastCompileResults)
            : this(scriptSource, lastCompileResults, String.Empty)
        {
        }
        public NotCompileableException(IScriptSourceHandle scriptSource, IScriptCompileResults lastCompileResults, string message)
            : base(message)
        {
            if (scriptSource == null)
                throw new ArgumentNullException("scriptSource");
            if (lastCompileResults == null)
                throw new ArgumentNullException("lastCompileResults");
            _ScriptSource = scriptSource;
            _LastCompileResults = lastCompileResults;

            _CustomMessageProvided = (message != String.Empty);
        }

        public IScriptSourceHandle ScriptSource
        {
            get { return _ScriptSource; }
        }

        public IScriptCompileResults LastCompileResults
        {
            get { return _LastCompileResults; }
        }

        public override string Message
        {
            get
            {
                if (_CustomMessageProvided)
                    return base.Message.Trim() + " The script's last compile was not successful.";
                else
                    return "The script's last compile was not successful.";
            }
        }
    }
}
